package com.zjs.controller;

import com.gyf.crm.domain.Customer;
import com.gyf.crm.service.CustomerService;
import com.mysql.jdbc.StringUtils;
import com.zjs.common.bean.ResponseResult;
import com.zjs.common.utils.UUID32Gen;
import com.zjs.pojo.QpNoticebill;
import com.zjs.service.QpNoticebillServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * @类名： QuPaiController
 * @说明： TODO
 * @作者：SS 苏帅出品
 * @时间：2019/12/11 16:22
 * @版本：1.0
 */
@RequestMapping(value = "qupai")
@Controller
public class QuPaiNoticebillController {

    @Autowired
    CustomerService customerService;

    @Autowired
    QpNoticebillServiceI qpNoticebillServiceI;

    //通过手机号验证是否存在 该客户
    @RequestMapping(value = "findCustomer.action")
    @ResponseBody
    public Customer findCustomerByTel(String tel){

        Customer customerByTel = customerService.findCustomerByTel(tel);

        return customerByTel;
    }



    //saveNoticeBill.action  添加业务通知单
    @RequestMapping(value = "saveNoticeBill.action")
    @ResponseBody
    public ResponseResult saveNoticeBill(QpNoticebill qpNoticebill){


        String id= UUID32Gen.gen32UUIDString();

        qpNoticebill.setId(id);

        //通过 用户的电话 判断是否是新用户
        Customer customerByTel = customerService.findCustomerByTel(qpNoticebill.getTelephone());

        //如果不为null 则是自动派单
        if (null!=customerByTel && !StringUtils.isNullOrEmpty(customerByTel.getDecidedzone_id())){


            qpNoticebill.setOrdertype("自动派单");


            qpNoticebillServiceI.saveQpNoticebill(qpNoticebill,customerByTel.getDecidedzone_id());



        }else{

            //否则是手动派单

            qpNoticebill.setOrdertype("手动派单");



            qpNoticebillServiceI.saveQpNoticebillHand(qpNoticebill);




        }






        return new ResponseResult(true,null);


    }


}
